package com.mars.basic.controller.admincontroller;

import com.mars.basic.allmain.entity.RoleEntity;
import com.mars.basic.allmain.vo.RoleVo;
import com.mars.basic.service.RoleService;
import com.mars.common.expetion.Code;
import com.mars.common.utils.QAssert;
import com.mars.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/role")
public class ARoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping("/add")
    public R add(@RequestBody RoleVo vo){
        QAssert.isTrue(roleService.checkRoleIsExists(vo), Code.ENTITY_EXIST_EXCEPTION,"该角色已存在");
        RoleEntity roleEntity = vo.build();
        roleService.getRoleRepository().save(roleEntity);
        return R.ok();
    }
}
